import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios'
import { Toast, Lazyload  } from 'vant'
import cookie from 'vue-cookies'

Vue.use(cookie)
Vue.use(Toast);
Vue.use(Lazyload, {
  lazyComponent: true,
  preload: 1.1
});

// axios.defaults.baseURL = 'http://172.30.24.29:9081/api'
axios.defaults.baseURL = 'http://127.0.0.1:9081/api'
// axios.defaults.baseURL = 'http://xyyhome.com/api'
axios.interceptors.request.use(config => {
  // 在发送请求之前做些什么
  let token = Vue.$cookies.get("token");
  if (token) {
    config.headers['token'] = token;
  }
  return config;
}, error => {
  Toast(error.response.data.msg);
});
axios.interceptors.response.use(null, error => {
  // 对响应错误做点什么
  Toast(error.response.data.msg);
  return Promise.reject(error);
});

// Vue.prototype.$cookie = cookie;
Vue.prototype.$ajax = axios
Vue.config.productionTip = false
// 添加请求拦截器


new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')


// axios.get("/wx/config").then(r => {
//   console.log(r.data)
//   wx.config(r.data);
// })
